package obecto.utility
{
	import flash.utils.Timer;
	import flash.utils.clearTimeout;

	public class TimeoutUtil
	{
		public static function setTimeout(closure:Function, delay:uint, ...params) : uint
		{
			var token : Object = 
				{
					closure: closure,
					params: params
				};
			
			var timeotId : uint = flash.utils.setTimeout(callClosure, delay, token);
			token["timeotId"] = timeotId;
			
			return timeotId;
		}		
		
		private static function callClosure(token : Object) : void
		{
			flash.utils.clearTimeout(token["timeotId"]);
			token["closure"].apply(null, token["params"]);
		}

	}
}